import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/assets.accountReceivable/dbGlfsc/list',
  save='/assets.accountReceivable/dbGlfsc/add',
  edit='/assets.accountReceivable/dbGlfsc/edit',
  deleteOne = '/assets.accountReceivable/dbGlfsc/delete',
  deleteBatch = '/assets.accountReceivable/dbGlfsc/deleteBatch',
  importExcel = '/assets.accountReceivable/dbGlfsc/importExcel',
  exportXls = '/assets.accountReceivable/dbGlfsc/exportXls',
  exportXlsBy = '/assets.accountReceivable/dbGlfsc/exportXlsBy',
  exportXlsForCheck = '/assets.accountReceivable/dbGlfsc/exportXlsForCheck',
  copyList = "/assets.accountReceivable/dbGlfsc/copyMonthList",
  batchAdd = "/assets.accountReceivable/dbGlfsc/batchAdd",
  earliestUnDeal = "/assets.accountReceivable/dbGlfsc/earliestUnDeal",
  copyAll = "/assets.accountReceivable/dbGlfsc/copyAll",
}

export  const apiGlfsc = Api;
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

export const listNoThenThisMonth = (params) => {
  if(params.htbh && params.htbh.replaceAll("*","")=="") {
    params.htbh = undefined;
  }
  if(params.qymc && params.qymc.replaceAll("*","")=="") {
    params.qymc = undefined;
  }
 console.log(params)
  if(!params.htbh && !params.qymc && !params.sfyf && params.exp==undefined){
    let yft = "";
    if((new Date().getMonth()+1)>=10){
      yft = ""+(new Date().getMonth()+1);
    }else{
      yft = "0"+(new Date().getMonth()+1);
    }
    let yf = new Date().getFullYear()+"-"+yft;
    params.sfyf = yf;
  }
  return defHttp.get({url: Api.list, params});
}

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
export const batchAdd = (params, isUpdate) => {
  let url = Api.batchAdd;
  return defHttp.post({url: url, params});
}

export const copyByMonth = (params) => {
  let url = Api.copyList;
  return defHttp.get({url: url, params});
}
